package com.isoftstone.project.system.service.impl;

import java.util.List;

import com.isoftstone.common.utils.Md5Utils;
import com.isoftstone.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.isoftstone.project.system.mapper.SysUserMapper;
import com.isoftstone.project.system.domain.SysUser;
import com.isoftstone.project.system.service.ISysUserService;
import com.isoftstone.framework.domain.Page;
import com.isoftstone.common.utils.text.Convert;

/**
 * systemService业务层处理
 *
 * @author guoX
 * @date 2020-10-27
 */
@Service
public class SysUserServiceImpl implements ISysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询system
     *
     * @param userId systemID
     * @return system
     */
    @Override
    public SysUser getSysUserById(String userId) {
        return sysUserMapper.getSysUserById(userId);
    }

    /**
     * 查询system列表
     *
     * @param page 分页参数
     * @return system
     */
    @Override
    public List<SysUser> getSysUserlistPage(Page page) {
        return sysUserMapper.getSysUserlistPage(page);
    }

    /**
     * 新增system
     *
     * @param sysUser system
     * @return 结果
     */
    @Override
    public int insertSysUser(SysUser sysUser) {
        sysUser.setPassWord(Md5Utils.getSimpleHash(sysUser.getPassWord()));
        return sysUserMapper.insertSysUser(sysUser);
    }

    /**
     * 修改system
     *
     * @param sysUser system
     * @return 结果
     */
    @Override
    public int updateSysUser(SysUser sysUser) {

        if(StringUtils.isNotEmpty(sysUser.getPassWord())){
            sysUser.setPassWord(Md5Utils.getSimpleHash(sysUser.getPassWord()));
        }
        return sysUserMapper.updateSysUser(sysUser);
    }

    /**
     * 删除system对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteSysUserByIds(String ids) {
        return sysUserMapper.deleteSysUserByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除system信息
     *
     * @param userId systemID
     * @return 结果
     */
    @Override
    public int deleteSysUserById(String userId) {
        return sysUserMapper.deleteSysUserById(userId);
    }

}
